package com.fenghongzhang.kuaishou.index.home.view.fragment;

import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.fenghongzhang.kuaishou.R;
import com.fenghongzhang.kuaishou.index.home.adapter.AttentFragmentAdapter;
import com.fenghongzhang.kuaishou.index.home.contract.AttentFragmentContract;
import com.fenghongzhang.kuaishou.index.home.entity.VideoBean;
import com.fenghongzhang.kuaishou.index.home.model.AttentModel;
import com.fenghongzhang.kuaishou.index.home.presenter.AttentPresenter;
import com.fenghongzhang.kuaishou.utils.ResponseBean;
import com.fenghongzhang.kuaishou.widget.PointImageView;
import com.fenghongzhang.mvp_lib.view.BaseFragment;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.BezierRadarHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * 首页中的关注
 *
 * @author fenghongzhang
 * @date 2021-05-16
 */
public class AttentFragment extends BaseFragment<AttentPresenter> implements AttentFragmentContract.IAttentlView {

    @BindView(R.id.header)
    BezierRadarHeader header;
    @BindView(R.id.attent_recycler)
    RecyclerView attentRecycler;
    @BindView(R.id.footer)
    ClassicsFooter footer;
    @BindView(R.id.smartRefresh)
    SmartRefreshLayout smartRefresh;

    private PointImageView point;
    private List<VideoBean> videoBeanList;
    private AttentFragmentAdapter attentFragmentAdapter;
    private static final String TAG = "AttentFragment";


    @Override
    public int bindLayout() {
        return R.layout.fragment_attent;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this,fragmentView);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.i(TAG, "onDestroyView: ");
    }

    @Override
    public void initData() {
        fragmentPresenter = new AttentPresenter(new AttentModel(), this);
        videoBeanList = new ArrayList<>();
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
//        gridLayoutManager.set
        attentRecycler.setLayoutManager(gridLayoutManager);
        attentFragmentAdapter = new AttentFragmentAdapter(R.layout.recycler_attent_layout, videoBeanList);
//        attentRecycler.addItemDecoration(new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL));
        attentRecycler.setAdapter(attentFragmentAdapter);
        fragmentPresenter.getVideoList();

        smartRefresh.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                smartRefresh.finishRefresh();
            }
        });

        smartRefresh.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                smartRefresh.finishLoadMore();
            }
        });
    }

    @Override
    public void showMsg(String msg) {

    }

    @Override
    public void initAdapter(ResponseBean<List<VideoBean>> list) {
        videoBeanList.addAll(list.getData());
        Log.i(TAG, "initAdapter: ");
        attentFragmentAdapter.notifyDataSetChanged();
    }
}
